package com.note7_10;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class WetherThread extends Thread{

	private Wether w;
	private Socket s;
	private String time;
	public WetherThread(Wether w,Socket s,String time){
		super();
		this.w = w;
		this.s = s;
		this.time = time;
	}
	
	public void run(){
		String time = "当前时间："+this.time;
		try {
			InputStream is = this.s.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			OutputStream os = this.s.getOutputStream();
			PrintWriter pw = new PrintWriter(os);
			while(true){
				String s = br.readLine();
				int i = Integer.valueOf(s);
				System.out.println(i);
				if(i == 1){	//气温
					pw.println(time+w.getAir());
				}else if(i == 2){	//风力
					pw.println(time+w.getWind());
				}else if(i ==3){	//pm2.5
					pw.println(time+w.getPm());
				}else if(i == 4){	//湿度
					pw.println(time+w.getHumidity());
				}else if(i ==5){	//全部
					pw.println(time+w.toString());
				}else if(i == 6){	//退出
					pw.println(w.quit());
					break;
				}else{
					pw.println("无法识别该操作！");
				}
				pw.flush();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(this.s != null){
				try {
					this.s.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
